package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.cache.TsCache;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.google.gson.JsonObject;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;

	/**
	 * 获取全部一级分类
	 * @return
	 */
	@GetMapping("findAllCategory1")
	Result<List<BaseCategory1>> findAllCategory1(){
		List<BaseCategory1> list = baseCategoryService.findAllCategory1();
		return Result.ok(list);
	}

	/**
	 * 根据一级分类ID，获取前七条置顶三级分类数据
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类ID，获取置顶三级分类数据")
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	public Result findTopBaseCategory3(@PathVariable Long category1Id){
		List<BaseCategory3> category3List=baseCategoryService.findTopBaseCategory3(category1Id);
		return Result.ok(category3List);
	}
	/**
	 * 根据一级分类Id，查询分类信息
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类Id，查询分类信息")
	@GetMapping("getBaseCategoryList/{category1Id}")
	public Result getBaseCategoryList(@PathVariable Long category1Id){
		JSONObject categoryList=baseCategoryService.getBaseCategoryList(category1Id);
		return Result.ok(categoryList);
	}
	/**
	 * 根据三级分类ID，查一级分类ID和二级分类ID
	 * @param category3Id
	 * @return
	 */
	@Operation(summary = "根据三级分类ID，查一级分类ID和二级分类ID")
	@GetMapping("/getCategoryView/{category3Id}")
	public Result getCategoryView(@PathVariable Long category3Id){
		BaseCategoryView categoryView = baseCategoryService.getCategoryView(category3Id);
		return Result.ok(categoryView);
	}

	/**
	 * 根据一级分类id,查询属性和属性值数据
	 * @param category1Id  一级分类ID
	 * @return  属性值列表数据，List<BaseAttribute>
	 */
	@Operation(summary = "根据一级分类id,查询属性和属性值数据")
	@GetMapping("/findAttribute/{category1Id}")
	public Result findAttribute(@PathVariable("category1Id") Long category1Id){
		List<BaseAttribute> attributeList=baseCategoryService.findAttribute(category1Id);
		return Result.ok(attributeList);
	}

	/**
	 * 获取所有专辑分类信息
	 * @return
	 */
	@Operation(summary = "获取所有专辑分类信息")
	@GetMapping("/getBaseCategoryList")
	public Result getBaseCategoryList(){
		List<JSONObject> categoryList=baseCategoryService.getBaseCategoryList();

		return Result.ok(categoryList);
	}




}

